package pg.objetosbasicos;

public class Vetor {
	public float x;
	public float y;
	public float z;		
	
	public Vetor() {}
	
	public Vetor(float x, float y, float z) {
		this.x = x;
		this.y = y;
		this.z = z;
	}
	
	public Vetor normalizar() {
		float norma = (float) ( Math.pow(this.x, 2) + Math.pow(this.y, 2) + Math.pow(this.z, 2) );
		norma = (float) Math.sqrt(norma);
		this.x /= norma;
		this.y /= norma;
		this.z /= norma;
		return this;
	}
	
	public static Vetor normalizar(Vetor aVetor) {
		Vetor result = new Vetor();
		float norma = (float)(Math.pow(aVetor.x,2)+Math.pow(aVetor.y,2)+Math.pow(aVetor.z,2));
		norma = (float)Math.sqrt(norma);
		result.x = aVetor.x/norma;
		result.y = aVetor.y/norma;
		result.z = aVetor.z/norma;
		return result;
	}

	public static Vetor produtoEscalar(float esc, Vetor v) {
		Vetor result = new Vetor();
		result.x = v.x * esc;
		result.y = v.y * esc;
		result.z = v.z * esc;
		return result;
	}
	
	public static float produtoEscalar(Vetor v1, Vetor v2) {
		return (v1.x * v2.x) + (v1.y * v2.y) + (v1.z * v2.z);
	}

	public static Vetor produtoVetorial(Vetor v1, Vetor v2) {
		Vetor result = new Vetor();
		result.x = (v1.y * v2.z) - (v2.y * v1.z);
		result.y = (v1.z * v2.x) - (v2.z * v1.x);
		result.z = (v1.x * v2.y) - (v2.x * v1.y);
		return result;
	}
	
	public static Vetor subtrair(Vetor v1, Vetor v2) {
		Vetor result = new Vetor();
		result.x = v2.x - v1.x;
		result.y = v2.y - v1.y;
		result.z = v2.z - v1.z;
		return result;
	}
	
	public static void main(String[] args) {
		Vetor v = new Vetor(255, 255, 255);
		v.normalizar();
		System.out.println(v.x);
		System.out.println(v.y);
		System.out.println(v.z);
	}
}
